﻿// 项目：	Guan.CMS.Domain - Guan.CMS
// 文件名：	ProductCategoryService.cs
// 
// 修改时间：2013-03-10 22:25
// 修改人：	Cooclsee

using System.Collections.Generic;
using System.Linq;
using Guan.CMS.Data.Repositories;
using Guan.CMS.Model.Entities;

namespace Guan.CMS.Domain.Services
{
    public class ProductCategoryService : IProductCategoryService
    {
        private readonly IProductCategoryRepository _productCategoryRepository;
        public ProductCategoryService(IProductCategoryRepository productCategoryRepository)
        {
            this._productCategoryRepository = productCategoryRepository;
        }

        public IEnumerable<ProductCategory> GetChildrenNodesById(int? id)
        {
            var list = _productCategoryRepository.GetList();
            if (id.HasValue && id != 0)
            {
                list = list.Where(c => c.ParentId == id.Value);
            }
            else
            {
                list = list.Where(c => !c.ParentId.HasValue || c.ParentId == 0);
            }
            return list.AsEnumerable();
        }
    }

    public interface IProductCategoryService
    {
        IEnumerable<ProductCategory> GetChildrenNodesById(int? id);
    }
}